import 'package:flutter/material.dart';
import 'mock/listData.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('demo'),
          ),
          body: HomeContent(),
        ),
        theme: ThemeData(primarySwatch: Colors.yellow));
  }
}

class HomeContent extends StatelessWidget {
  // List list = [];

  // HomeContent() {
  //   for (var i = 0; i < 20; i++) {
  //     list.add(ListTile(
  //       title: Text('我是标题$i'),
  //     ));
  //   }
  // }
  List<Widget> _getData() {
    List<Widget> list = [];
    for (var i = 0; i < 20; i++) {
      list.add(ListTile(
        title: Text('我是标题$i'),
      ));
    }
    return list;
  }

  List<Widget> _getMockData() {
    var list = listData.map((item) {
      return ListTile(
        title: Text(item['title']),
        trailing: const Icon(
          Icons.headset_rounded,
          color: Colors.red,
          size: 30,
        ),
        subtitle: Text(item['subTitle']),
      );
    });
    return list.toList();
  }

// builder构造
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: listData.length,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(listData[index]["title"]),
            subtitle: Text(listData[index]["subTitle"]),
          );
        });
  }
}
